# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=cglm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.7.7
pkgrel=1
pkgdesc="OpenGL Mathematics (glm) for C (mingw-w64)"
arch=('any')
url="https://github.com/recp/cglm"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme")
options=(!strip staticlibs !buildflags)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/recp/cglm/archive/v${pkgver}.tar.gz")
sha256sums=('2614a61cafc5d2e908364795943b9eebc8be3231128e4c77498e9c3448d365cc')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../"${_realname}-${pkgver}"/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST}
  make

  cd "${srcdir}/${_realname}-${pkgver}/docs"
  ${MINGW_PREFIX}/bin/sphinx-build source ${_realname}
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}"/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/cglm/LICENSE
  install -Dm644 cglm.pc "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/cglm.pc

  cd "${srcdir}/${_realname}-${pkgver}/docs"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/share/doc
  cp -r ${_realname} "${pkgdir}${MINGW_PREFIX}"/share/doc/
}
